<template>
  <div class="app-container calendar-list-container">
    <div v-if="!opShow">
      <search :list="queryList" :queryEntity="queryEntity"></search>
      <buttons :showQuery="true" :showBack="false" @query="doQuery" :list="btnList" :disabled="disabled" placeholder="订单号" :permissions="permissions" @view="doView"></buttons>
      <grid :columns="columns" :multi="false" :url="queryUrl" ref="mainGrid" height="auto" diffHeight="125" @change="rowCilck" :queryEntity="queryEntity" :pagination="true"
        :permissions="permissions" @in="doIn" @cancel="doCancel" @view="doView"></grid>
    </div>
  </div>
</template>

<script>
import request from '@/router/axios'
import url from '@/const/apiURL'
import grid from '@/components/Grid'
import buttons from '@/components/Buttons'
import search from '@/components/Search'
import { Message, MessageBox } from 'element-ui'
import { mapGetters } from 'vuex'
import { YesOrNoFormatter, WmsOrderStatusFormatter } from '@/const/dict'
import { colunms } from '@/const/colunms'
import { dict } from '@/const/dict'
import { bgColor } from '@/const/bgColor'
import { queryField } from '@/const/query'

export default {
  components: { grid, buttons, search },
  data () {
    return {
      queryUrl: url.ORDER_IN_LIST_URL,
      disabled: true,
      opShow: false,
      queryEntity: { key: 'key' },
      columns: [
        {
          label: '操作', width: 100, prop: 'op', align: 'center', template: 'op', opList: [
            { name: '入库', clickName: 'in', auth: 'order_in_in', confirm: true, valueProp: "orderStatus", showValue: ["UN_DO", "CANCEL"] },
            { name: '取消', clickName: 'cancel', auth: 'order_in_cancel', confirm: true, valueProp: "orderStatus", showValue: ["DO"] },
            { name: '查看', clickName: 'view', auth: 'order_in_view' }
          ]
        },
        { label: '入库单号', width: 180, prop: 'orderNo', align: 'left' },
        { label: '仓库名称', width: 100, prop: 'warehouseName', align: 'left' },
        { label: '业务单号', width: 180, prop: 'businessCode', align: 'left' },
        { label: '大货订单', width: 180, prop: 'businessOrderNo', align: 'left' },
        { label: '入库时间', width: 160, prop: 'orderTime', align: 'center' },
        { label: '操作人', width: 80, prop: 'orderUserName', align: 'center' },
        { label: '订单状态', width: 80, prop: 'orderStatus', align: 'center', formatter: WmsOrderStatusFormatter, template: 'bgColor', bgColor: bgColor().WmsOrderStatus },
        { label: '创建时间', width: 100, prop: 'createTime', align: 'center' }
      ],
      btnList: [
        //{ name: '入库', type: 'primary', icon: 'edit', click: 'in', auth: 'order_in_in', ctr: true, confirm: true },
        // { name: '取消', type: 'primary', icon: 'edit', click: 'cancel', auth: 'order_in_cancel', ctr: true, confirm: true },
        // { name: '查看', type: 'primary', icon: 'edit', click: 'view', auth: 'order_in_view', ctr: true }
      ],
      queryList: [
        { name: '入库单号', type: 'text', prop: 'orderNoLike', placeholder: "入库单号" },
        { name: '创建时间', type: 'date', prop: 'startTime', placeholder: "" },
        { name: '----', type: 'date', prop: 'endTime', placeholder: "", },
        { name: '业务单号', type: 'text', prop: 'businessCode', placeholder: "业务单号" },
        { name: '仓库名称', type: 'query', prop: 'warehouseCode', rowValue: 'warehouseCode', rowName: 'warehouseName', placeholder: "仓库名称", url: url.WAREHOUSE_USABLE_URL, columns: colunms().warehouseColumns },
        { name: '订单编号', type: 'query', prop: 'businessOrderNo', rowValue: 'orderNo', rowName: 'orderNo', url: url.ORDER_LIST_URL, columns: colunms().orderColumns, pagination: true, queryList: queryField().order, queryEntity: { status: 1 }, autoInput: true },
        { name: '入库状态', type: 'select', prop: 'orderStatus', placeholder: "入库状态", values: dict().WmsOrderStatus, label: 'name', value: 'value' }
      ]
    }
  },
  created () {
  },
  computed: {
    ...mapGetters([
      'permissions'
    ])
  },
  methods: {
    doView (row) {
      // const row = this.$refs['mainGrid'].getSelectOne()
      if (row) {
        this.$router.push({ path: '/wms/in/view', query: { orderNo: row.orderNo } })
      }
    },
    doQuery (text) {
      this.$refs['mainGrid'].doQuery(text)
    },
    rowCilck (row) {
      this.disabled = row.length == 0
    },
    cancel () {
      this.opShow = false
    },
    inOp (orderNo) {
      return request({
        url: url.ORDER_IN_IN_URL,
        method: 'post',
        data: { 'key': 'key' },
        params: { 'orderNo': orderNo }
      })
    },
    cancelOp (orderNo) {
      return request({
        url: url.ORDER_IN_CANCEL_URL,
        method: 'post',
        data: { 'key': 'key' },
        params: { 'orderNo': orderNo }
      })
    },
    doIn (row) {
      //const row = this.$refs.mainGrid.getSelectOne()
      if (row) {
        this.inOp(row.orderNo).then((data) => {
          if (data) {
            this.$refs['mainGrid'].reload()
          }
        })
      }
    },
    doCancel (row) {
      // const row = this.$refs.mainGrid.getSelectOne()
      if (row) {
        this.cancelOp(row.orderNo).then((data) => {
          if (data) {
            this.$refs['mainGrid'].reload()
          }
        })
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
